#!/bin/python
from vBaum import *
from math import *
import queue
import threading
from time import time

scale = 16
splinePoints = [Vector3(0,5,0)*scale,
	Vector3(3,4,20)*scale,
	Vector3(10,5,25)*scale,
	Vector3(20,15,15)*scale,
	Vector3(25,15,0)*scale,
	Vector3(5,5,0)*scale,
	Vector3(-10,-10,5)*scale,
	Vector3(-10,25,10)*scale,
	Vector3(20,-5,10)*scale,
	Vector3(16,5,-10)*scale]

def fixLong(n):
	if n >= 1<<31:
		n -= 1<<32
	return n
	
def createSphereLinear(fPos):
	sphere = Sphere(2+fPos*20)
	sphere.setColor(fixLong(0x00ff00ff))
	return sphere
	
def createSphereSin(fPos):
	sphere = Sphere(15+10*sin(fPos*50))
	sphere.setColor(fixLong(floor(0x0000ffff * fPos)))
	return sphere
	
def createSpline1():
	#extrude spline using createSphereLinear
	knotLinear = Spline(splinePoints, True, createSphereLinear)
	knotLinear.exportAsPly("knotLinear", 10, 50)

def createSpline2():
	#extrude spline using createSphereSin
	knotSin = Spline(splinePoints, True, createSphereSin)
	knotSin.exportAsPly("knotSin", 10, 50)
	
t0 = time()
createSpline1()
createSpline2()
t1 = time()
print("Execution time ST: " + str(t1 - t0))
	
t0 = time()
thread1 = threading.Thread(None, createSpline1)
thread2 = threading.Thread(None, createSpline2)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
t1 = time()
print("Execution time MT: " + str(t1 - t0))

